import axios from '@/libs/api.request'
import config from '@/config'

/*
* 获取验证码
* */
export const getVerify=()=> {
  let url = 'https://img-blog.csdnimg.cn/20200709225907963.png'
  if (config.env != 'dev') {
    let num = Math.ceil(Math.random() * 10000);//生成一个随机数（防止缓存）
    url = config.baseUrl.pro + "getVerifyCode?" + num;
  }
  return url;
}

/*
* 登录
* */
export const login = ({ userName, password,verifyCode }) => {
  const data = {
    userName,
    password,
    verifyCode
  }
  return axios.request({
    url: 'login',
    data,
    method: 'post'
  })
}

/*
* 获取菜单用户菜单信息
* */
export const getMenuList = (userId) => {
  return axios.request({
    url: 'getRouter',
    method: 'post'
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
